//
//  CommpanyCell.m
//  PTravel
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 李涵. All rights reserved.
//

#import "CommpanyCell.h"

@implementation CommpanyCell
- (void)dealloc
{
    [_title release];
    [_userName release];
    [_views release];
    [_viewsImage release];
    [_replysImage release];
    [_replys release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(15, 8, BOUNDS.size.width-30, 1)];
    //self.title.backgroundColor = [UIColor redColor];
    self.title.font = [UIFont systemFontOfSize:14];
    [self addSubview:self.title];
    [_title release];
    
    self.userName = [[UILabel alloc] initWithFrame:CGRectMake(15, 55, 1, 15)];
    self.userName.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.userName];
    [_userName release];
    
    self.prettyDate = [[UILabel alloc] initWithFrame:CGRectMake(self.userName.frame.origin.x+self.userName.frame.size.width+10, self.userName.frame.origin.y, 100, 15)];
    self.prettyDate.font = [UIFont systemFontOfSize:12];
    self.prettyDate.textColor = [UIColor colorWithRed:1.000 green:0.221 blue:0.847 alpha:1.000];
    [self addSubview:self.prettyDate];
    [_prettyDate release];
    
    self.viewsImage = [[UIImageView alloc] initWithFrame:CGRectMake(BOUNDS.size.width-120, self.userName.frame.origin.y+5, 15, 15)];
    self.viewsImage.image = [UIImage imageNamed:@"lookImage"];
    [self addSubview:self.viewsImage];
    [_viewsImage release];
    
    self.views = [[UILabel alloc] initWithFrame:CGRectMake(self.viewsImage.frame.origin.x+20, self.viewsImage.frame.origin.y, 40, 15)];
    self.views.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.views];
    [_views release];
    
    self.replysImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.views.frame.origin.x+40, self.userName.frame.origin.y+5, 15, 15)];
    self.replysImage.image = [UIImage imageNamed:@"iconfont-pinglun.png"];
    [self addSubview:self.replysImage];
    [_replysImage release];
    
    self.replys = [[UILabel alloc] initWithFrame:CGRectMake(self.replysImage.frame.origin.x+20, self.viewsImage.frame.origin.y, 40, 15)];
    self.replys.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.replys];
    [_replys release];
}
- (void)setCommpany:(Commpany *)commpany
{
    if (_commpany != commpany) {
        [_commpany release];
        _commpany = [commpany retain];
    }
    
    self.title.text = commpany.title;
    self.title.numberOfLines = 2;
    CGFloat height =  [AppTools heightForContent:self.title.text font:14.0 width:BOUNDS.size.width-30];
    CGRect tempFrame = self.title.frame;
    tempFrame.size.height = height;
    self.title.frame = tempFrame;
    
    self.userName.text = commpany.username;
    CGSize size =[commpany.username sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
    CGRect tempFrame1 = self.userName.frame;
    tempFrame1.size.width = size.width;
    self.userName.frame = tempFrame1;
    
    
    self.views.text = [NSString stringWithFormat:@"%d", commpany.views.intValue];
    self.replys.text = [NSString stringWithFormat:@"%d",commpany.replys.intValue];
    self.prettyDate.frame = CGRectMake(self.userName.frame.origin.x+self.userName.frame.size.width+10, self.userName.frame.origin.y, 100, 15);
    self.prettyDate.text = [AppTools prettyDateWithReference:[NSDate dateWithTimeIntervalSince1970:commpany.publish_time]];
    self.title.textColor = TEXTCOLOR;
    self.userName.textColor = TEXTCOLOR;
    self.replys.textColor = TEXTCOLOR;
    self.views.textColor = TEXTCOLOR;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
